Declare Function IsAppRunning Lib "RSHELL.DLL"(EXEname As String) As Integer
Declare Function Launch Lib "RSHELL.DLL"(hWnd As Integer, Task As Integer, FileToLaunch As String) As Integer
Declare Sub CloseApp Lib "RSHELL.DLL"(EXEname As String)
Declare Function ListInit Lib "RSHELL.DLL"(Sorted As Integer) As Integer
Declare Function ShowList Lib "RSHELL.DLL"(Id As Integer, Title As String) As Integer
Declare Function SelectedFromList Lib "RSHELL.DLL"(Id As Integer, SelectedItem As Integer, ListValue As String) As Integer
Declare Sub ListStop Lib "RSHELL.DLL"(Id As Integer)
Declare Function PopulateListBox Lib "RSHELL.DLL"(Id As Integer, Item As String) As Integer
Sub Main
    Id = ListInit(- 1)  'Sorted, pass zero value ListInit(0) will result in usoretd listing
    Items = PopulateListBox(Id, "Load Write")
    Items = PopulateListBox(Id, "Load C:\SAMPLE.TXT file")
    Items = PopulateListBox(Id, "Unload Write")
    Items = PopulateListBox(Id, "Unload Notepad")
    k = ShowList(Id, "Sample Listing")
    If k > 0 Then
       'Do the first and up
       i = 0
       While i < k
           i = i + 1  
           x = SelectedFromList(Id, i, a$)
           a$ = Left$(a$, x)
           Select Case a$
              Case "Load Write"
                 StartApp "WRITE.EXE"
              Case "Load C:\SAMPLE.TXT file"
                 StartApp "C:\SAMPLE.TXT"
              Case "Unload Write"
                 ShutOff "WRITE.EXE"
              Case "Unload Notepad"
                 ShutOff "NOTEPAD.EXE"
           End Select   
       Wend
    End If
    'close the listing before terminating the macro
    'note: listing can be shared by all macros even by users in LAN
    '      as long as Id is the same. The ListStop function clears it.
    'you can keep practically unlimited number of listings in memory 
    '      the ListInit function will return the next available Id number
    ListStop Id
End Sub
Sub StartApp(FileToActivate$)
       'what is the hWnd value of the WinWord form?
    winhWnd = IsAppRunning("WINWORD.EXE")
    Task = 0  'Open
          '1   Print  
    x = Launch(winhWnd, Task, FileToActivate$)
End Sub

Sub ShutOff(FileToTerminate$)
    CloseApp FileToTerminate$
End Sub
